package com.hxk.juc.thread.syn8d;

import java.util.concurrent.TimeUnit;

/***
 * //结论，synchronized (obj)锁的不是ｔｈｉｓ对象，所以ｍ２不会受ｍ１的影响，会直接执行互不干预
 */
public class SynchronizedCase3 {
    public synchronized void m1(){
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("m1");
    }

    Object obj = new Object();
    public void m2(){
        synchronized (obj){
            System.out.println("m2");
        }
    }

    public static void main(String[] args) {
        SynchronizedCase3 case3 = new SynchronizedCase3();
        new Thread(()->{case3.m1();},"001").start();
        new Thread(()->{case3.m2();},"002").start();

    }
}
